﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using System.ComponentModel;
using System.Web.Configuration;
using System.Web.Security;

namespace HospitalSystem
{
    public partial class findchild : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
         
            
            if (!IsPostBack)
            {

                BindData();
                Session["CID"] = null;
                Session["LastName"] = null;
                Session["FirstName"] = null;
                Session["CaseNo"] = null;
                Session["PSNumber01"] = null;
               

            }
            
        
        }


        private void MessageBox(string msg)
        {
            Label lbl = new Label();
            lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
            Page.Controls.Add(lbl);





        }




        
        protected void BindData()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection scon = new SqlConnection(constr);

            scon.Open();

            SqlCommand cmd = new SqlCommand("SELECT a.CID as CID,a.FirstName as FirstName,a.LastName as LastName,b.Name as DisabilityType FROM Person a join DisabilityType b on a.DisabilityType=b.DisabilityCode where a.CID like @text or a.FirstName like @text or a.Lastname like @text", scon);
            cmd.Parameters.AddWithValue("@text", "%"+ Session["find"]+ "%");
           


            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            childlist.DataSource = ds;
            childlist.DataBind();
            scon.Close();

            //if (reader.Read())
            //{


            //}
            //else
            //{
            //    MessageBox("ไม่พบการค้นหาครับ  กรุณาลงทะเบียนเด็กก่อนที่ปุ่มลงทะเบียน");
            //}
          

















        }

        protected void familylist_SelectedIndexChanged(object sender, GridViewPageEventArgs e)
        {
            childlist.PageIndex = e.NewPageIndex;
            BindData();
        }

        //protected void BindDatadek()
        //{
        //    SelectStat.Text = string.Empty;
        //    bool selectorChecked3 = false;

        //    DataTable dt2 = new DataTable();
        //    dt2.Columns.Add("CID");
        //    dt2.Columns.Add("FirstName");
        //    dt2.Columns.Add("LastName");
        
           
        //    foreach (GridViewRow row in GridView1.Rows)
        //    {
        //        RadioButton cb = (RadioButton)row.FindControl("CaseSelector3");
        //        if (cb != null && cb.Checked)
        //        {
        //            selectorChecked3 = true;

        //            DataRow dr2;
        //            dr2 = dt2.NewRow();
        //            string CID = GridView1.Rows[row.RowIndex].Cells[0].Text;
        //            string FirstName = GridView1.Rows[row.RowIndex].Cells[1].Text;
        //            string LastName = GridView1.Rows[row.RowIndex].Cells[2].Text;
        //            SelectStat.Text += string.Format(CID);
        //            Label2.Text = string.Format(FirstName);
        //            Label3.Text = string.Format(LastName);
        //            dt2.Rows.Add(CID, FirstName, LastName);


        //        }
        //    }
        //    SelectStat.Visible = selectorChecked3;


        //}

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        protected void CaseSelector3_CheckedChanged(object sender, EventArgs e)
        {
            //BindDatadek();
           // crepsnumber();
           // psnumbertolabel();
            sendsession();



        }

        protected void sendsession()
        {
            Session["CID"] = SelectStat.Text;
            Session["FirstName"] = Label2.Text;
            Session["LastName"] = Label3.Text;


            Response.Redirect("~/indexchild.aspx");


        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Session["CID"] = null;
            Response.Redirect("~/reg.aspx");

  
          
        }

       

    }
}